var $ = require("../../utils/Ajax.js");
Page({
  data: {
    NextStatus: false,
    Prompt: "身份证号输入错误，请检查并重新输入",
    Name: null,
    Mobile: null,
    Bank: null,
    SubBranch: null,
    CardNum: null
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "填写银行卡信息"
    })
  },

  // 银行卡号
  CardNum: function(e){
    var CardNum = e.detail.value;
    this.setData({
      CardNum: CardNum
    })
  },

  // 卡类型
  Bank: function (e) {
    var Bank = e.detail.value;
    this.setData({
      Bank: Bank
    })
  },

  // 支行信息
  SubBranch: function (e) {
    var SubBranch = e.detail.value;
    this.setData({
      SubBranch: SubBranch
    })
  },

  // 姓名
  Name: function(e){
    var Name = e.detail.value;
    this.setData({
      Name: Name
    })
  },

  // 手机号
  Phone: function(e){
    var Phone = e.detail.value;
    this.setData({
      Phone: Phone
    })
  },

  // 点击下一步
  NextStatus: function(){
    var Name = this.data.Name;
    var Phone = this.data.Phone;
    var Bank = this.data.Bank;
    var SubBranch = this.data.SubBranch;
    var CardNum = this.data.CardNum;
    if (Name == '' || Name == null || Phone == '' || Phone == null || Bank == '' || Bank == null || SubBranch == '' || SubBranch == null || CardNum == '' || CardNum == null){
      wx.showToast({
        title: '必填信息不能为空',
        icon: 'none',
        duration: 1500
      })
    }else{
      this.setData({
        NextStatus: true
      })
    }
  },

  // 点击绑定银行卡
  AddBank: function(){
    $.Ajax("api/addUserCard", "POST", {
      name: this.data.Name,
      mobile: this.data.Phone,
      bank: this.data.Bank,
      subBranch: this.data.SubBranch,
      cardNum: this.data.CardNum,
    }, function (res) {
      wx.showToast({
        title: res.m,
        icon: 'none',
        duration: 1500
      })
      if(res.s){
        setTimeout(function(){
          wx.navigateBack({
            delta: 1
          })
        },2000)
      }
    })
  }
})